package com.qidianit.mes.masterdata.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qidianit.mes.common.pojo.MesResult;
import com.qidianit.mes.masterdata.service.WorkshopService;
import com.qidianit.mes.pojo.Workshop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2025/8/1 10:18
 * @description
 */
@RestController
@RequestMapping("/workshop")
public class WorkshopController {
    @Autowired
    private WorkshopService workshopService;

    @PostMapping // 这里不需要写url，只要是post请求，就默认执行这个方法
    public MesResult<Workshop> createWorkshop(@RequestBody Workshop workshop) {
        return workshopService.saveWorkshop(workshop);
    }

    @GetMapping("/list")
    public MesResult<Page<Workshop>> list(Workshop workshop, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue="10") int pageSize){
        return workshopService.getWorkshopList(workshop, pageNum, pageSize);
    }

    @GetMapping("/{id}")
    public MesResult<Workshop> getWorkshopById(@PathVariable Integer id) {
        return workshopService.getWorkshopById(id);
    }
    @PutMapping// 不需要url，只要是put请求就直接进这个方法
    public MesResult<Workshop> updateWorkshop(@RequestBody Workshop workshop) {
        return workshopService.updateWorkshop(workshop);
    }
    @DeleteMapping("/{id}")
    public MesResult<Workshop> deleteWorkshop(@PathVariable Integer id) {
        return workshopService.deleteWorkshop(id);
    }
    @DeleteMapping("/batch")
    public MesResult<Workshop> deleteWorkshopByIds(@RequestBody Integer[] ids) {
        return workshopService.deleteWorkshopByIds(ids);
    }
}
